﻿package extremefx.ui {
	import extremefx.drawing.geometry.RectangleShape;
	import extremefx.geom.Size;
	
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;		

	/**
	 * @author Marcelo Volmaro
	 */
	public class RectangleComponent extends AnimatedComponent {
		private var _myrec:RectangleShape;

		public function RectangleComponent(pName:String) {
			_text = pName;
			super();
			
			tabEnabled(false);
			
			_myrec = new RectangleShape();
			_myrec.color = 0xff0000;
			_visualUI.addChild(_myrec);
		}

		override public function get preferredSize():Size {
			return new Size(80, 40);
		}

		protected override function _draw():void {
			_visualUI.x = _x;
			_visualUI.y = _y;
			_myrec.width = _width;
			_myrec.height = _height;
			
			if (_text) {
				if (!_tf) {
					var tf:TextField = _tf = new TextField();
					tf.autoSize = TextFieldAutoSize.LEFT;
					tf.condenseWhite = true;
				
					var tformat:TextFormat = new TextFormat("Verdana", 12);
					tf.defaultTextFormat = tformat;
					_visualUI.addChild(tf);
				}
				
				_tf.text = _text;
			}
		}

		private var _tf:TextField;
		private var _text:String;

		public function setTitle(text:String):void {
			_text = text;
		}
	}
}
